﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;

namespace BLL
{
    public class FriendManager
    {
        /// <summary>
        ///     获取指定分组中的所有好友信息
        /// </summary>
        /// <param name="ItemId" type="string">
        ///     <para>
        ///         分组Id
        ///     </para>
        /// </param>
        /// <returns>
        ///     返回null , 则表示不存在该分组或者该分组不存在好友
        /// </returns>
        public Dictionary<String,String> GetFriendByItemId(String ItemId)
        {
            DataTable DT_FRIENDINFO = Globle.friendService.GetFriendByItemId(ItemId);
            if (DT_FRIENDINFO != null && DT_FRIENDINFO.Rows.Count > 0)
            {
                Dictionary<String,String> DIC_FRIENDINFO =new Dictionary<string, string>();
                for (int i = 0; i < DT_FRIENDINFO.Rows.Count; i++)
                {
                    DIC_FRIENDINFO.Add(DT_FRIENDINFO.Rows[i]["Friend_UserId"].ToString(),
                                       Globle.userManager.GetUsernameById(
                                           DT_FRIENDINFO.Rows[i]["Friend_UserId"].ToString()));
                }
                return DIC_FRIENDINFO;
            }
            return null;
        }

        /// <summary>
        ///     添加指定好友到指定分组
        /// </summary>
        /// <param name="ItemId">分组ID</param>
        /// <param name="FriendUsername">好友用户名</param>
        /// <returns>返回false , 则表示添加失败</returns>
        public int AddFriend(int ItemId, String FriendUsername)
        {
            return Globle.friendService.AddFriend(ItemId, int.Parse(Globle.userManager.GetUserId(FriendUsername)));
        }

        /// <summary>
        ///     添加指定好友到指定分组
        /// </summary>
        /// <param name="ItemId">分组ID</param>
        /// <param name="FriendUserId">好友用户ID</param>
        /// <returns>返回false , 则表示添加失败</returns>
        public int AddFriend(int ItemId, int FriendUserId)
        {
            return Globle.friendService.AddFriend(ItemId, FriendUserId);
        }

        /// <summary>
        ///     删除用户中指定分组ID和好友用户名
        /// </summary>
        /// <param name="ItemId">分组ID</param>
        /// <param name="FriendName">好友用户名</param>
        /// <returns>返回false, 则表示删除好友失败</returns>
        public bool DeleteFriend(int ItemId, String FriendName)
        {
            return DeleteFriend(ItemId, int.Parse(Globle.userManager.GetUserId(FriendName)));
        }

        /// <summary>
        ///     删除用户中指定分组ID和好友ID
        /// </summary>
        /// <param name="ItemId">分组ID</param>
        /// <param name="FriendName">好友ID</param>
        /// <returns>返回false, 则表示删除好友失败</returns>
        public bool DeleteFriend(int ItemId, int FriendId)
        {
           return  Globle.friendService.DeleteFriend(ItemId, FriendId);
        }

        /// <summary>
        ///     从指定的分组集合中删除在其中某个分组下的好友
        /// </summary>
        /// <param name="ItemsId">分组集合</param>
        /// <param name="FriendId">好友ID</param>
        /// <returns>返回false, 则表示删除好友失败</returns>
        public bool DeleteFriend(int[] ItemsId, int FriendId)
        {
            return Globle.friendService.DeleteFriend(ItemsId, FriendId);
        }
    }
}
